// 文件路径: com.city.java.base.config.WebMvcConfig.java
package com.city.java.base.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.nio.file.Paths;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${user.dir}")
    private String userDir;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置静态资源访问路径，映射到前端项目的图片目录
        String frontendImagePath = Paths.get(userDir, "front", "src", "assets", "imgs").toUri().toString();
        registry.addResourceHandler("/imgs/**")
                .addResourceLocations(frontendImagePath);
    }
}
